<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true" size="small">
      <el-form-item label="ID、用户名" prop="userParam">
        <el-input
            v-model="queryParams.userParam"
            placeholder="请输入用户ID、用户名搜索"
            clearable
            style="width: 240px"
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="checkStatus">
        <el-select v-model="queryParams.checkStatus">
          <el-option key="2" label="审核通过" value="2"></el-option>
          <el-option key="3" label="审核失败" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="mb8" style="display: flex;align-items: center;justify-content: space-between">
      <el-col class="tag-group">
        <span>审核开关：</span><el-switch v-model="content.open" @change="handleCheckChange"></el-switch>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="default"
            icon="el-icon-delete"
            size="mini"
            @click="handleBatchDelete"
        >删除</el-button>
      </el-col>
    </div>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" prop="id" width="80" align="center" sortable />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户名" align="center" prop="username" />
      <el-table-column label="日期" align="center" prop="createTime	">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime	) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="图片" align="center" prop="source">
        <template slot-scope="scope" v-if="scope.row.source">
          <el-image :src="scope.row.source" :preview-src-list="[scope.row.source]" style="width: 50px;height: 50px" fit="cover"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="checkStatus">
        <template slot-scope="scope">
          <span>{{ scope.row.checkStatus === 1 ? '待审核' : scope.row.checkStatus === 2 ? '审核成功' : '审核失败' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核说明" align="center" prop="text" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              style="color: #f00"
              @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <!--内容查看弹窗-->
    <el-dialog title="内容查看" :visible.sync="open" width="40%" append-to-body :close-on-click-modal="false">
      <video :src="videoUrl" controls style="width: 100%;height: 400px;"></video>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="open = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getAutoCheck, deleteAuthCheck, getAutoCheckStatus, saveAuthCheck } from "@/api/shuiyin/shuiyin";

export default {
  name: "CommentManage",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组id
      ids: '',
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 租户管理表格数据
      list: [],
      // 查询参数
      queryParams: {
        checkStatus: null,
        userInfo: null,
        type: 2,
        pageNum: 1,
        pageSize: 10,
      },
      content: {},
      open: false,
      videoUrl: '',
    };
  },
  created() {
    this.getDetail();
    this.getList();
  },
  methods: {
    async getDetail() {
      const { data } = await getAutoCheckStatus(2);
      if (data) {
        this.content = data
      } else {
        this.content = {
          open: false,
          type: 2
        }
      }
    },
    /** 查询租户管理列表 */
    getList() {
      this.loading = true;
      getAutoCheck(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id).join(',')
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 批量删除
    handleBatchDelete() {
      if (!this.ids) {
        this.$modal.msgWarning('请先选择需要删除的数据！')
        return
      }
      this.handleDelete()
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除所选数据项？').then(function() {
        return deleteAuthCheck(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 内容查看操作 */
    handleView(url) {
      if (!url) {
        return
      }
      this.videoUrl = url;
      this.open = true;
    },
    // 开关自动审核
    async handleCheckChange(open) {
      await saveAuthCheck(this.content)
      this.$modal.msgSuccess(`${open ? '开启' : '关闭'}成功！`)
      this.getDetail()
    }
  }
};
</script>
<style>
</style>